//
//  YYEAnswerTableViewCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/4.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYEStudentTableViewCell.h"

@interface YYEStudentTableViewCell ()

@property (nonatomic,strong) UIImageView *backIV;
@property (nonatomic,strong) UIImageView *headImg;
@property (nonatomic,strong) UIImageView *sexImg;
@property (nonatomic,strong) UILabel *phoneLabel;
@property (nonatomic,strong) UILabel *nameLabel;


@end

@implementation YYEStudentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.contentView.backgroundColor = GeneralBackColor;
        
        self.backIV = [[UIImageView alloc]init];
        self.backIV.image = [UIImage imageNamed:@"noBorder"];
        [self.contentView addSubview:self.backIV];
        
        self.headImg = [[UIImageView alloc]init];
        self.headImg.image = [UIImage imageNamed:@"noBorder"];
        [self.backIV addSubview:self.headImg];
        
        self.sexImg = [[UIImageView alloc]init];
        self.sexImg.image = [UIImage imageNamed:@"noBorder"];
        [self.backIV addSubview:self.sexImg];
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textColor = [UIColor colorWithHexString:@"#666666"];
        self.nameLabel.font = [UIFont systemFontOfSize:13];
        [self.backIV addSubview:self.nameLabel];
        
        self.phoneLabel = [[UILabel alloc] init];
        self.phoneLabel.textColor = [UIColor colorWithHexString:@"#666666"];;
        self.phoneLabel.font = [UIFont systemFontOfSize:13];
        [self.backIV addSubview:self.phoneLabel];
        


        //        self.questionLabel.text = @"为啥我这里没能实现功能？";
        //        self.nameLabel.text = @"Jolin";
        //        self.timeLabel.text = @"2017.7.23";
        //        self.answerNameLabel.text = @"陈晨讲师的回答";
        //        self.answerLabel.text = @"直接运行实现不了，用debug运行~";
        
    }
    return self;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.backIV makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(UIEdgeInsetsMake(0, 8, 0.5, 8));
    }];
    
    [self.headImg makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backIV.left).offset(29);
        make.top.equalTo(self.backIV.top).offset(15);
        make.size.equalTo(CGSizeMake(41, 41));
    }];
    self.headImg.layer.masksToBounds = YES;
    self.headImg.layer.cornerRadius = 41/2.0;
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImg.right).offset(13);
        make.centerY.equalTo(self.headImg.centerY);
    }];
    
    [self.sexImg makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.right).offset(4.6);
        make.centerY.equalTo(self.nameLabel.centerY);
        make.size.equalTo(CGSizeMake(10, 10));

    }];
    
    [self.phoneLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.backIV.right).offset(-13);
        make.centerY.equalTo(self.nameLabel.centerY);
    }];
    

    
}

- (void)setAnswerModel:(YYELessonAnswerModel *)answerModel {
    _answerModel = answerModel;
    
    [_headImg sd_setImageWithURL:[NSURL URLWithString:answerModel.img] placeholderImage:nil];
    self.nameLabel.text = answerModel.name;

    if ([answerModel.sex isEqualToString:@"男"]) {
        _sexImg.image = [UIImage imageNamed:@"bg_m"];
    }
    else {
        _sexImg.image = [UIImage imageNamed:@"bg_w"];

    }
    self.phoneLabel.text = answerModel.username;

    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

